<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreateCapacityPoolReportTable extends AbstractMigration
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function up()
    {
        $table = $this->table('capacity_pool_report', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '产能池报表']);
        $table->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '主键ID'])
            ->addColumn('tenant_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '租户ID'])
            ->addColumn('project_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '项目id'])
            ->addColumn('team_category_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '团队环节ID'])
            ->addColumn('attribute', 'string', ['default' => '', 'limit' => 255, 'comment' => '团队环节属性'])
            ->addColumn('capacity_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '产能ID（即岗位ID）'])
            ->addColumn('report_month', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '月份'])
            ->addColumn('capacity_num', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '产能'])
            ->addColumn('desc', 'text', ['null' => true, 'comment' => '备注（用户IDs｜方案）'])
            ->addColumn('type', 'integer', ['limit' => 255, 'null' => false, 'signed' => false, 'default' => 1, 'comment' => '类型： 1=自动生成,2=上传导入,3=锁定产能,4=解决方案'])
            ->addColumn('updated', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '更新时间'])

            ->addIndex(['report_month', 'capacity_id', 'tenant_id'], ['type' => 'normal', 'name' => 'tenant_report_month'])
            ->addIndex(['team_category_id', 'report_month'], ['type' => 'normal', 'name' => 'tenant_capacity_id']);
        // 创建表
        $table->create();
    }

    public function down()
    {
        $this->table('capacity_pool_report')->drop()->save();
    }
}
